package cn.ckx.coding.moudle.user.queue;

import cn.ckx.coding.moudle.user.config.RabbitMqDelayConfig;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

/**
 * @ClassName QuesDelayCustomer
 * @Description 消费者
 * @Author c
 * @Date 2020/12/25
 * @Version 1.0
 **/
@Component
@Slf4j
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class QuesCustomer {
    
    //普通消息

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue("sync.chunyu.sorting.handler"),
            exchange = @Exchange("sync-chunyu-doctorSorting"),
            key = "sorting"
    ))
       
    
    //延迟消息
    
    @RabbitListener(queues = {RabbitMqDelayConfig.DELAY_QUEUE})
    @RabbitHandler
    public void test1(String id) {
        log.info("延迟队列测试1:消费时间-{},id为-{}", LocalDateTime.now(), id);
    }

    
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(value = RabbitMqDelayConfig.DELAY_QUEUE_2),
            exchange = @Exchange(value = RabbitMqDelayConfig.DELAY_EXCHANGE, type = "x-delayed-message" ), 
            key = RabbitMqDelayConfig.DELAY_ROUTING_KEY_2
    ))
    public void testQues2(String id){
        log.info("延迟队列测试2:消费时间-{},id为-{}", LocalDateTime.now(), id);
    }

}
